local f = io.open("letter.txt","r+")
local f2 = io.open("letter2.txt","a+")
local s = {}
function copy(file1,file2)
    file1:seek("set")
    local strTable = {}
    for line in file1:lines() do 
        strTable[#strTable + 1] = line
        table.sort(strTable,function (a,b)
            return string.byte(a) < string.byte(b)
        end)
    end
    for i = 1,#strTable do 
        file2:write(strTable[i] .. "\n")
    end
end

if(f ~= nil and f2 ~= nil) then
    copy(f,f2)
    f:close()
    f2:close()
end


